<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/filter/limitTo.js?message=docs(limitTo)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.3.13/src/ng/filter/limitTo.js#L3' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">limitTo</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - filter in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>Creates a new array or string containing only a specified number of elements. The elements
are taken from either the beginning or the end of the source array, string or number, as specified by
the value and sign (positive or negative) of <code>limit</code>. If a number is used as input, it is
converted to a string.</p>

</div>




<div>
  

  
  <h2>Usage</h2>
  <h3>In HTML Template Binding</h3>
  
    <pre><code>{{ limitTo_expression | limitTo : limit}}</code></pre>
  

  <h3>In JavaScript</h3>
  <pre><code>$filter(&#39;limitTo&#39;)(input, limit)</code></pre>

  
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        input
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-array">Array</a><a href="" class="label type-hint type-hint-string">string</a><a href="" class="label type-hint type-hint-number">number</a>
      </td>
      <td>
        <p>Source array, string or number to be limited.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        limit
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-string">string</a><a href="" class="label type-hint type-hint-number">number</a>
      </td>
      <td>
        <p>The length of the returned array or string. If the <code>limit</code> number
    is positive, <code>limit</code> number of items from the beginning of the source array/string are copied.
    If the number is negative, <code>limit</code> number  of items from the end of the source array/string
    are copied. The <code>limit</code> will be trimmed if it exceeds <code>array.length</code></p>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
  
  <h3>Returns</h3>
<table class="variables-matrix return-arguments">
  <tr>
    <td><a href="" class="label type-hint type-hint-array">Array</a><a href="" class="label type-hint type-hint-string">string</a></td>
    <td><p>A new sub-array or substring of length <code>limit</code> or less if input array
    had less than <code>limit</code> elements.</p>
</td>
  </tr>
</table>


  
  <h2 id="example">Example</h2><p>

<div>
  <a ng-click="openPlunkr('examples/example-example102', $event)" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>

  <div class="runnable-example"
      path="examples/example-example102"
      module="limitToExample">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;script&gt;&#10;  angular.module(&#39;limitToExample&#39;, [])&#10;    .controller(&#39;ExampleController&#39;, [&#39;$scope&#39;, function($scope) {&#10;      $scope.numbers = [1,2,3,4,5,6,7,8,9];&#10;      $scope.letters = &quot;abcdefghi&quot;;&#10;      $scope.longNumber = 2345432342;&#10;      $scope.numLimit = 3;&#10;      $scope.letterLimit = 3;&#10;      $scope.longNumberLimit = 3;&#10;    }]);&#10;&lt;/script&gt;&#10;&lt;div ng-controller=&quot;ExampleController&quot;&gt;&#10;  Limit {{numbers}} to: &lt;input type=&quot;number&quot; step=&quot;1&quot; ng-model=&quot;numLimit&quot;&gt;&#10;  &lt;p&gt;Output numbers: {{ numbers | limitTo:numLimit }}&lt;/p&gt;&#10;  Limit {{letters}} to: &lt;input type=&quot;number&quot; step=&quot;1&quot; ng-model=&quot;letterLimit&quot;&gt;&#10;  &lt;p&gt;Output letters: {{ letters | limitTo:letterLimit }}&lt;/p&gt;&#10;  Limit {{longNumber}} to: &lt;input type=&quot;number&quot; step=&quot;1&quot; ng-model=&quot;longNumberLimit&quot;&gt;&#10;  &lt;p&gt;Output long number: {{ longNumber | limitTo:longNumberLimit }}&lt;/p&gt;&#10;&lt;/div&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="protractor.js"
      type="protractor"
      language="js">
      <pre><code>var numLimitInput = element(by.model(&#39;numLimit&#39;));&#10;var letterLimitInput = element(by.model(&#39;letterLimit&#39;));&#10;var longNumberLimitInput = element(by.model(&#39;longNumberLimit&#39;));&#10;var limitedNumbers = element(by.binding(&#39;numbers | limitTo:numLimit&#39;));&#10;var limitedLetters = element(by.binding(&#39;letters | limitTo:letterLimit&#39;));&#10;var limitedLongNumber = element(by.binding(&#39;longNumber | limitTo:longNumberLimit&#39;));&#10;&#10;it(&#39;should limit the number array to first three items&#39;, function() {&#10;  expect(numLimitInput.getAttribute(&#39;value&#39;)).toBe(&#39;3&#39;);&#10;  expect(letterLimitInput.getAttribute(&#39;value&#39;)).toBe(&#39;3&#39;);&#10;  expect(longNumberLimitInput.getAttribute(&#39;value&#39;)).toBe(&#39;3&#39;);&#10;  expect(limitedNumbers.getText()).toEqual(&#39;Output numbers: [1,2,3]&#39;);&#10;  expect(limitedLetters.getText()).toEqual(&#39;Output letters: abc&#39;);&#10;  expect(limitedLongNumber.getText()).toEqual(&#39;Output long number: 234&#39;);&#10;});&#10;&#10;// There is a bug in safari and protractor that doesn&#39;t like the minus key&#10;// it(&#39;should update the output when -3 is entered&#39;, function() {&#10;//   numLimitInput.clear();&#10;//   numLimitInput.sendKeys(&#39;-3&#39;);&#10;//   letterLimitInput.clear();&#10;//   letterLimitInput.sendKeys(&#39;-3&#39;);&#10;//   longNumberLimitInput.clear();&#10;//   longNumberLimitInput.sendKeys(&#39;-3&#39;);&#10;//   expect(limitedNumbers.getText()).toEqual(&#39;Output numbers: [7,8,9]&#39;);&#10;//   expect(limitedLetters.getText()).toEqual(&#39;Output letters: ghi&#39;);&#10;//   expect(limitedLongNumber.getText()).toEqual(&#39;Output long number: 342&#39;);&#10;// });&#10;&#10;it(&#39;should not exceed the maximum size of input array&#39;, function() {&#10;  numLimitInput.clear();&#10;  numLimitInput.sendKeys(&#39;100&#39;);&#10;  letterLimitInput.clear();&#10;  letterLimitInput.sendKeys(&#39;100&#39;);&#10;  longNumberLimitInput.clear();&#10;  longNumberLimitInput.sendKeys(&#39;100&#39;);&#10;  expect(limitedNumbers.getText()).toEqual(&#39;Output numbers: [1,2,3,4,5,6,7,8,9]&#39;);&#10;  expect(limitedLetters.getText()).toEqual(&#39;Output letters: abcdefghi&#39;);&#10;  expect(limitedLongNumber.getText()).toEqual(&#39;Output long number: 2345432342&#39;);&#10;});</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-example102/index.html" name="example-example102"></iframe>
  </div>
</div>


</p>

</div>


